#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    int maxProduct(vector<int>& nums) {
        if (nums.size() == 0) {
            return 0;
        }
        int max = INT32_MIN;
        int max_num = 1;
        int min_num = 1;
        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] < 0) {
                swap(max_num, min_num);
            }
            max_num = std::max(max_num * nums[i], nums[i]);
            min_num = std::min(min_num * nums[i], nums[i]);
            max = std::max(max, max_num);
        }
        return max;
    }
};

int main() {
    vector<int> input = {2, -5, -2, -4, 3};
    Solution solution;
    int output = solution.maxProduct(input);
    cout << output << endl;
    return 0;
}

